package com.hy.heath.config;

import com.hy.heath.common.BusinessException;
import com.hy.heath.common.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理业务异常
     */
    @ExceptionHandler(BusinessException.class)
    public R<?> handleBusinessException(BusinessException e) {
        return R.fail(e.getCode(), e.getMessage());
    }

    /**
     * 处理其他未捕获异常（可选）
     */
    @ExceptionHandler(Exception.class)
    public R<?> handleException(Exception e) {
        return R.fail(500, "系统繁忙，请稍后再试");
    }
}